<template>
  <div>
    <el-row>
      <el-breadcrumb separator-class="el-icon-arrow-right">
        <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
        <el-breadcrumb-item>订单管理</el-breadcrumb-item>
        <el-breadcrumb-item>订单列表</el-breadcrumb-item>
      </el-breadcrumb>
    </el-row>
    <el-card class="box-card">
      <el-row>
        <el-input
          placeholder="请输入内容"
          v-model="isGetorderList.query"
          class="searchInput"
          clearable
        >
          <el-button
            slot="append"
            icon="el-icon-search"
            @click="getOrderList"
          ></el-button>
        </el-input>
      </el-row>
      <el-row>
        <el-table :data="orderList.goods" style="width: 100%" border>
          <el-table-column type="index" label="#"> </el-table-column>
          <el-table-column prop="order_number" label="订单编号">
          </el-table-column>
          <el-table-column prop="order_price" label="订单价格">
          </el-table-column>
          <el-table-column prop="order_pay" label="是否付款">
            <template slot-scope="scope">
              <el-tag v-if="scope.row.order_pay == '1'">已付款</el-tag>
              <el-tag type="danger" v-else>未付款</el-tag>
            </template>
          </el-table-column>
          <el-table-column prop="is_send" label="是否发货"> </el-table-column>
          <el-table-column prop="create_time" label="下单时间">
          </el-table-column>
          <el-table-column label="操作">
            <template>
              <el-button type="primary" icon="el-icon-edit"></el-button>
              <el-button
                type="success"
                icon="el-icon-location-information"
                @click="inquireExpressage()"
              ></el-button>
            </template>
          </el-table-column>
        </el-table>
      </el-row>
      <el-row>
        <el-pagination
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page="isGetorderList.pagenum"
          :page-sizes="[10, 20, 50, 100]"
          :page-size="isGetorderList.pagesize"
          layout="total, sizes, prev, pager, next, jumper"
          :total="orderList.total"
        >
        </el-pagination>
      </el-row>
      <el-dialog
        title="修改地址"
        :visible.sync="dialogVisible"
        width="50%"
        :before-close="handleClose"
      >
        <div class="block">
          <el-timeline>
            <el-timeline-item
              :timestamp="item.time"
              placement="top"
              v-for="(item, index) in amendExpressageSite"
              :key="index"
            >
              <el-card>
                <h4>{{ item.context }}</h4>
                <p>{{ item.time }}</p>
              </el-card>
            </el-timeline-item>
          </el-timeline>
        </div>
        <span slot="footer" class="dialog-footer">
          <el-button @click="dialogVisible = false">取 消</el-button>
          <el-button type="primary" @click="dialogVisible = false"
            >确 定</el-button
          >
        </span>
      </el-dialog>
    </el-card>
  </div>
</template>

<script>
export default {
  data() {
    return {
      isGetorderList: {
        query: "",
        pagenum: 1,
        pagesize: 10,
      },
      dialogVisible: false,
      orderList: {},
      amendExpressageSite: [],
    };
  },
  methods: {
    // 分页控件控制每页显示
    handleSizeChange(val) {
      this.isGetorderList.pagesize = val;
      this.getOrderList();
    },
    // 分页控件切换页数
    handleCurrentChange(val) {
      this.isGetorderList.pagenum = val;
      this.getOrderList();
    },
    // 获取订单数据列表
    async getOrderList() {
      const { data: res } = await this.$http({
        url: "/orders",
        method: "get",
        params: {
          ...this.isGetorderList,
        },
      });
      if (res.meta.status !== 200) return this.$message.error(res.meta.msg);
      this.orderList = res.data;
      this.orderList.goods.forEach((item) => {
        item.create_time = this.dayjs(item.create_time).format(
          "YYYY年MM月DD日HH时MM分"
        );
        item.update_time = this.dayjs(item.update_time).format(
          "YYYY年MM月DD日HH时MM分"
        );
      });
    },
    handleClose() {},
    async inquireExpressage() {
      const { data: res } = await this.$http({
        url: `/kuaidi/1106975712662`,
        method: "get",
      });
      if (res.meta.status !== 200) return this.$message.error(res.meta.msg);
      this.dialogVisible = true;
      this.amendExpressageSite = res.data;
    },
  },

  created() {
    this.getOrderList();
  },
};
</script>

<style lang="less" scoped>
.searchInput {
  width: 500px;
  margin-bottom: 20px;
}
</style>
